<%@page import="java.util.regex.Matcher"%>
<%@page import="java.util.regex.Pattern"%>
<%@ page language="java" pageEncoding="UTF-8"%>
<%!
public static final String REG_PHONE = "^\\d{7,}$";
public static final String REG_EMAIL = "^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$";
public static final String REG_IP = "\\b((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\b";
public static final String REG_ID_CARD_1 = "^[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}$"; 
public static final String REG_ID_CARD_2 = "^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([0-9]|X)$";
public static final String REG_ZIP_CODE = "\\d{6}(?!\\d)";
public static final String REG_EQ_NUM_6 = "^(\\d)\\1\\1\\1\\1\\1$";//匹配6个相同的数字

public static void main(String[] args) {
	String cheak = "011111";
	System.out.println(checkZipCode(cheak));
}

/**
 * 判断邮政编码
 * @param cheak 检验的字符串
 * @param reg 匹配规则
 * @return
 */
public static boolean checkZipCode(String zipcode){
	if(!check(zipcode, REG_ZIP_CODE)){
		return false;
	}  
	if(check(zipcode, REG_EQ_NUM_6)){
		return false;
	}
	return true;
}
//return (/^\d{11}$/.test(str)) && !(/^(\d)\1\1\1\1\1\1\1\1\1\1$/.test(str));


/**
 * 判断
 * @param cheak 检验的字符串
 * @param reg 匹配规则
 * @return
 */
public static boolean check(String cheak,String reg){
	Pattern p = Pattern.compile(reg);  
	Matcher m = p.matcher(cheak);  
	return m.matches();  
}

/**
 * 判断身份证
 * @param cheak 检验的字符串
 * @param reg 匹配规则
 * @return
 */
public static boolean checkIdCard(String idcard){
	if(!checkIdCard1(idcard) && !checkIdCard2(idcard)){
		return false;
	}
	return true;  
}

/**
 * 判断二代身份证
 * @param cheak 检验的字符串
 * @param reg 匹配规则
 * @return
 */
public static boolean checkIdCard1(String idcard){
	return check(idcard, REG_ID_CARD_1);
	//return m.matches();  
}

/**
 * 判断二代身份证
 * @param cheak 检验的字符串
 * @param reg 匹配规则
 * @return
 */
public static boolean checkIdCard2(String idcard){
	return check(idcard, REG_ID_CARD_2);
	//return m.matches();  
}

/**
 * 判断电话号码
 * 简单判断
 * @param phone
 * @return
 */
public static boolean checkPhone(String phone){
	Pattern p = Pattern.compile(REG_PHONE);  
	Matcher m = p.matcher(phone);  
	return m.matches();  
}

/**
 * 判断邮箱
 * 简单判断
 * @param phone
 * @return
 */
public static boolean checkEmail(String email){
	Pattern p = Pattern.compile(REG_EMAIL);  
	Matcher m = p.matcher(email);  
	return m.matches();  
}

/**
 * 判断IP格式
 * 简单判断
 * @param phone
 * @return
 */
public static boolean checkIP(String ip){
	Pattern p = Pattern.compile(REG_IP);  
	Matcher m = p.matcher(ip);  
	return m.matches();  
}
%>